/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package cpasl;

import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.RadioButton;
import javafx.scene.control.TextField;
import javafx.scene.control.ToggleGroup;
import javafx.scene.layout.GridPane;

/**
 *
 * @author seanm_000
 */
public class RaceGridPane extends GridPane {
    
    public RaceGridPane() {
        setAlignment(Pos.CENTER);
        setHgap(15);
        setVgap(15);
        
        Label raceLabel = new Label("What is your race?");
        final ToggleGroup raceGroup = new ToggleGroup();
        RadioButton nativeButton = new RadioButton("American Indian or Alaska Native");
        nativeButton.setUserData("A");
        nativeButton.setToggleGroup(raceGroup);
        nativeButton.setSelected(true);
        RadioButton asianButton = new RadioButton("Asian");
        asianButton.setUserData("B");
        asianButton.setToggleGroup(raceGroup);
        RadioButton blackButton = new RadioButton("Black or African American");
        blackButton.setUserData("C");
        blackButton.setToggleGroup(raceGroup);
        RadioButton pacificButton = new RadioButton("Native Hawaiian or other Pacific Islander");
        pacificButton.setUserData("D");
        pacificButton.setToggleGroup(raceGroup);
        RadioButton whiteButton = new RadioButton("White");
        whiteButton.setUserData("E");
        whiteButton.setToggleGroup(raceGroup);
        RadioButton otherButton = new RadioButton("Other:");
        otherButton.setUserData("F");
        otherButton.setToggleGroup(raceGroup);
        final TextField otherTextField = new TextField();
        RadioButton naButton = new RadioButton("Prefer not to respond");
        naButton.setUserData("G");
        naButton.setToggleGroup(raceGroup);
        
        Button nextButton = new Button();
        nextButton.setText("Next");
        nextButton.setId("next-button");
        nextButton.setOnAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent event) {
                String userData = (String) ((RadioButton) raceGroup.getSelectedToggle()).getUserData();
                CpaslManager.getInstance().setRace(userData);
                if (userData.equals("F")) {
                    CpaslManager.getInstance().setOtherRace(otherTextField.getText());
                }
                else {
                    CpaslManager.getInstance().setOtherGender("");
                }
               CpaslManager.getInstance().switchToDisplay(Groups.HAND, 0);
            }
        });
        
        add(raceLabel, 0, 0);
        add(nativeButton, 0, 1);
        add(asianButton, 0, 2);
        add(blackButton, 0, 3);
        add(pacificButton, 0, 4);
        add(whiteButton, 0, 5);
        add(otherButton, 0, 6);
        add(otherTextField, 1, 6);
        add(naButton, 0, 7);
        add(nextButton, 0, 8);
    }
    
}
